module MC.Order {
	export class orderXuanze {
		public constructor() {
			this.init();
		}
		private init() {
			$('.orderDockingPage').on('click','[out_trade_no] .xuanzehezuo',function () {
				MC.click(() => {
					MC.msg.confirm("该操作无法撤销,未选择的工厂的保证金将会返还;是否确认选择该工厂合作?", () => {
						let out_trade_no = $(this).parent().attr('out_trade_no');
						MC.api("xuanzehezuo", {
							out_trade_no: out_trade_no
						}, (json: any) => {
							window.open('/h5/order/kongzhitai.html?out_trade_no=' + out_trade_no, '_self');
							 
						});
					});
				});
			});

			MC.apiD('orderXuanze',{
				bale:MC.get('bale')
			},(data:any)=>{
			//	console.log(data);
				for(let i=0;i<data.list.length;i++){
					this.addli(data.bale,data.list[i]);
				}				
			}); 
		}

		private addli(bale:any,li:any){
			let status=``;
			if(li.show_kongzhiqi){
				status=`<a class="button kongzhitai" href="/h5/order/kongzhitai.html?out_trade_no=`+li.out_trade_no+`">控制台</a>`;	
			}else{
				status=`<span>`+li.status+`</span>`;
			}
			let html=` <li class="detail clearfix">
                <img class="detail__span" ziliaoid="`+li.fid+`"
                     src="`+li.user.head+`" >
                <ul>
                    <li>
                        <span>抢单用户名：</span>
                        <span class="name">`+li.user.name+`</span>
                        `+status+`
                    </li>
                    <li out_trade_no="`+li.out_trade_no+`">
                        <span>工厂名称：</span>
                        <span class="com_name">`+li.com_name+`</span>
                        <a class="button xuanzehezuo">选中合作</a>
                    </li>
                    <li>
                        <span>抢单时间：</span>
                        <span class="timedate">`+li.created_at+`</span>
                        <a class="button jiaoliu" call="`+li.user.jiguang_id+`">商务交流</a>
                    </li>
                </ul>
            </li>`;
			if(bale.select){
				html=` <li class="detail clearfix">
                <img class="detail__span" ziliaoid="`+li.fid+`"
                     src="`+li.user.head+`">
                <ul>
                    <li>
                        <span>抢单用户名：</span>
                        <span class="name">`+li.user.name+`</span>
                        `+status+`
                    </li>
                    <li out_trade_no="`+li.out_trade_no+`">
                        <span>工厂名称：</span>
                        <span class="com_name">`+li.com_name+`</span> 
                    </li>
                    <li>
                        <span>抢单时间：</span>
                        <span class="timedate">`+li.created_at+`</span> 
						<a class="button jiaoliu" call="`+li.user.jiguang_id+`">商务交流</a>
                    </li>
                </ul>
            </li>`;
			}


			$('.myOrderList').append(html);
		}

	}
}